
function splitArrayIntoChunks(array, chunkSizes) {
    const result = [];
    let index = 0;

    // 首先按照指定的chunkSizes分割数组
    for (let size of chunkSizes) {
        result.push(array.slice(index, index + size));
        index += size;
    }

    // 检查是否有剩余元素，并按照3个一组进行分割
    while (index < array.length) {
        result.push(array.slice(index, index + 3));
        index += 3;
    }

    return result;
}

console.log(splitArrayIntoChunks([1, 2, 3, 4, 5, 6, 7], [2, 1]));